<?php
/**
 * @Name  : NodeModel.php
 * @Author: yashuai<1762910894@qq.com>
 */

namespace App\Http\Model\Rbac;

use App\Http\Model\BaseModel;
use Illuminate\Support\Facades\DB;

class NodeModel extends BaseModel
{

    protected $primaryKey = 'NodeID';

    protected $table      = 'admin_node';

    /**
     * @Desc   获取用户所有菜单节点ID数组
     * @param  int $userId
     * @return array
     * @author yashuai<1762910894@qq.com>
     */
    public static function getUserNodeIDArray(int $userId = 0)
    {
        return DB::table(RoleNodeModel::tableName() . ' as n')
            ->leftJoin(UserRoleModel::tableName() . ' as r', 'n.RoleID', '=', 'r.RoleID')
            ->where('r.UserID', '=', $userId)
            ->pluck('n.NodeID')->toArray();
    }

}
